﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Nova_DAL;
using System.Data.Common;

public partial class Storage_Bill_List : System.Web.UI.Page
{
    DbHelper access = new DbHelper();
    DbCommand cmd = null;
    string strSQL = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gv_Bind();
        }
    }

    protected string getSQL()
    {
        HttpCookie WType = Request.Cookies["WType"];

        strSQL = @"SELECT TBA.StockNo,MAX(CONVERT(varchar(100), TBA.CDT, 23))AS CDT,MAX(TBT.TRAY_ID)
	                        FROM TBill_AddStorage TBA 
	                        LEFT JOIN TAddStorage_List TAL ON TAL.StockNo=TBA.StockNo
	                        LEFT JOIN TBase_Storage TBS ON TAL.Sec_Mat_ID=TBS.Sec_Mat_ID
                            LEFT JOIN TBase_Interface TBI ON TBI.Sec_Mat_ID=TBS.Sec_Mat_ID
	                        LEFT JOIN TRel_TrayPosContainer TRT ON TRT.ContainerID= TBS.ContainerID
	                        LEFT JOIN TBase_TrayPos TBT ON TRT.Relations_ID=TBT.Relations_ID
	                        WHERE TBT.TRAY_ID IS NOT NULL AND (TAL.TS02 = '" + WType.Value.ToString().Trim() + "' OR 'FSSC'='" + WType.Value.ToString().Trim() + "')";

        if (txt_Stock_No.Text != "")
        {
            strSQL += " AND TBA.StockNo LIKE '%" + txt_Stock_No.Text.Trim() + "%'";
        }
        strSQL+=" GROUP BY TBA.StockNo ORDER BY CDT DESC";

        return strSQL;

    }

    protected void gv_Bind()
    {
        cmd = access.GetSqlStringCommond(getSQL());
        gv.DataSource = access.ExecuteDataSet(cmd);
        gv.DataBind();
    }

    protected void ibtnSearch_Click(object sender, ImageClickEventArgs e)
    {
        gv_Bind();
    }

    protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gv.PageIndex = e.NewPageIndex;
        gv_Bind();  //重新绑定GridView
    }
    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label LabStock_No = (Label)e.Row.Cells[1].FindControl("LabStock_No");

            Label LabNumber = (Label)e.Row.Cells[1].FindControl("LabNumber");

            e.Row.Attributes.Add("onclick", "parent.window.returnValue='" + LabNumber.Text.Trim() + "," + LabStock_No.Text.Trim() + "," + e.Row.Cells[2].Text.Trim().Replace("&nbsp;", "") + "';parent.window.close();");

            //设置悬浮鼠标指针形状为"小手"   
            e.Row.Attributes["style"] = "Cursor:hand";
        }
    }

    protected void ibrn_S_Click(object sender, ImageClickEventArgs e)
    {
        cmd = access.GetSqlStringCommond(getSQL());
        gv.DataSource = access.ExecuteDataSet(cmd);
        gv.DataBind();
    }
}
